/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dw2;
import java.awt.Color;
import java.awt.Image;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
/**
 *
 * @author Administrator
 */
public class Bomb extends NPC {


        protected static ArrayList<Image> image = new ArrayList<Image>();
        protected int cycle_count = 0;
        protected Particle particles[] = new Particle[500];
        protected int particle_life = 60;


       public Bomb(int x, int y, int direction_to_face,int points){
           super(x,y-image.get(0).getHeight(null),direction_to_face,points);
           graphics.add(new DWGraphics_Animation(image.get(0),25,2)); //Blink1
           graphics.add(new DWGraphics_Animation(image.get(0),10,2)); //Blink2
       }

       public static void initImage(Image images[])
       {
        image.addAll(Arrays.asList(images));
       }

       public void action(Main mainparent,Worm player)
      {
        cycle_count++;
        this.player = player;

        if(state == 0){
            Blink1();
        }
        if(state == 1){
            Blink2();

        }
        if(state == 2) {
            explode(mainparent, player);
        }
        if(player.hitWorm(graphics.get(graphics_index).getBounds())== true){
            explode(mainparent, player);
            player.hurtWorm(25);  
        }

        if(cycle_count > 150) {
            state = 1;
        }
        if(cycle_count > 300){
            state = 2;
        }

    }

    public void explode(Main mainparent,Worm player) {

        mainparent.removeNPC(this);
        mainparent.bang.play();
        int center_x = x + graphics.get(graphics_index).getWidth()/2;
        int center_y = y + graphics.get(graphics_index).getHeight();

        for(int w = 0;w<death_particle_count;w++)
        {
            Particle pR = new Particle(center_x,center_y,Color.RED,2,5);
           // pR.toggleRemoveOnGround();
            pR.setLife(particle_life);
            pR.setGravity(0.1);
            mainparent.addParticle(pR);
            particles[w] = pR;

            Particle pO = new Particle(center_x,center_y,Color.ORANGE,2,5);
          //  pO.toggleRemoveOnGround();
            pO.setLife(particle_life);
            pO.setGravity(0.1);
            mainparent.addParticle(pO);
            particles[w+1] = pO;

           // mainparent.addParticle(new Particle(center_x,center_y,Color.,2,5));

            Particle pY = new Particle(center_x,center_y,Color.YELLOW,2,5);
          //  pY.toggleRemoveOnGround();
            pY.setLife(particle_life);
            pY.setGravity(0.1);
            mainparent.addParticle(pY);
            particles[w+2] = pO;

            Particle pB = new Particle(center_x,center_y,Color.BLACK,2,5);
          //  pB.toggleRemoveOnGround();
            pB.setLife(particle_life);
            pB.setGravity(0.1);
            mainparent.addParticle(pB);
            particles[w+3] = pB;


        }
    }
    public void Blink1(){
        graphics_index = 0;
    }
    public void Blink2(){
        graphics_index = 1;
    }

}
